#!/usr/bin/python3

import paramiko
import time
from datetime import datetime


ips = ["192.168.99.100" ,"10.110.111.17","10.110.111.22","10.110.111.26","10.110.110.190","10.110.110.125", "10.110.110.126", "10.110.110.254", "10.110.111.14"]
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

for ip in ips:
    ssh_client.connect(hostname=ip, username="huawei", password="123456")
    cmd = ssh_client.invoke_shell()

    cmd.send("dis version\n")
    time.sleep(1)
    jieguo = cmd.recv(10000)
    jieguo = jieguo.decode("utf-8")
    str_name = jieguo.splitlines()[-1][1:-1]
    shijian = datetime.now()
    newfile = str_name+"_%s_%s_%s_%s_%s_vrpcfg.zip"%(shijian.year,shijian.month,shijian.day,shijian.hour,shijian.minute)
    #cmd.send("sys\n")
    cmd.send("ftp 192.168.99.101\n")
    time.sleep(1)
    cmd.send("ftpuser\n")
    time.sleep(1)
    cmd.send("ftp123\n")
    time.sleep(1)
    cmd.send("put vrpcfg.zip %s\n"%newfile)
    time.sleep(4)
    cmd.send("q\n")
    time.sleep(2)
    output = cmd.recv(10000)
    print(output.decode("utf-8"))
    ssh_client.close()